package com.frxuexi.park2212.merchant

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.base.BaseViewModel
import com.frxuexi.lib_base.entity.MerchantBean
import com.frxuexi.lib_base.entity.MerchantBeanItem
import com.frxuexi.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MerchantViewModel @Inject constructor(val apiService: ApiService):BaseViewModel(){
    var getMerchants = MutableLiveData<MerchantBean>()
    var getMerchantById = MutableLiveData<MerchantBeanItem>()

    var approve = MutableLiveData<MerchantBeanItem>()

    var addMerchant = MutableLiveData<MerchantBeanItem>()


    fun getMerchants(){
        httpRequest({apiService.getMerchants()},getMerchants::postValue)
    }

    fun getMerchantById(id:Int){
        httpRequest({apiService.getMerchantById(id)},getMerchantById::postValue)
    }

    fun approve(id:Int){
        httpRequest({apiService.approve(id)},approve::postValue)
    }

    fun reject(id:Int){
        httpRequest({apiService.reject(id)},approve::postValue)
    }

    fun addMerchant(item:MerchantBeanItem){
        httpRequest({apiService.addMerchant(toBody(item))},addMerchant::postValue)
    }
}